<template>
	<view class="myheader">
		<div class="space-between">
			<div class="logo-box">
				<image src="../../static/logo.png" mode="widthFix" class="logo"></image>
			</div>
			<div class="flex1 colum">
				<image :src="uinfo.avatar" class="avatar bor50" :class="{typeAvatar2:type==2}"
					mode="aspectFill">
				</image>
				<div class="f20 ctheme nowrap" :class="{typeName2:type==2}">{{uinfo.username || uinfo.tpaddress}}</div>
			</div>
			<div class="logo-box align-end colum">
				<image src="../../static/message.png" mode="widthFix" class="message-icon mb20"></image>
				<uni-data-select :localdata="locales" @change="onLocaleChange">
					<div class="lan-box center">
						<div class="f18">{{getName()}}</div>
						<u-icon name="list" color="#000" size="14"></u-icon>
					</div>
				</uni-data-select>
			</div>
		</div>
		<div class="btheme cfff">
			<slot></slot>
		</div>
	</view>
</template>

<script>
	export default {
		name: "myheader",
		data() {
			return {
				locales: [{
						text: '中文',
						value: 'zh-Hans'
					}, {
						text: 'English',
						value: 'en'
					},
					{
						text: '한국인',
						value: 'ko'
					},
					{
						text: '日本語',
						value: 'ja'
					},
					{
						text: 'Tiếng Việt',
						value: 'vi'
					}
				],
				uinfo: uni.getStorageSync('uinfo')
			};
		},
		props: {
			type: {
				type: String,
				default: ''
			}
		},
		created() {
			this.setTabBarItem()
		},
		methods: {
			getName() {
				let name
				this.locales.forEach((v) => {
					if (v.value == this.$i18n.locale) {
						name = v.text
					}
				})
				return name
			},
			onLocaleChange(e) {
				uni.setLocale(e);
				this.$i18n.locale = e;
				this.setTabBarItem()
			},
			setTabBarItem() {
				let that = this
				uni.setTabBarItem({
					index: 0,
					text: that.$t("tabbar.shou")
				})
				uni.setTabBarItem({
					index: 1,
					text: that.$t("tabbar.gong")
				})
				uni.setTabBarItem({
					index: 2,
					text: that.$t("tabbar.wode")
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.myheader {
		height: 360rpx;
		overflow: hidden;

		.btheme {
			background: #FFFFFF;
			box-shadow: 2rpx 6rpx 6rpx 6rpx rgba(160, 24, 102, .1);
			border-radius: 20rpx 20rpx 0 0;
			margin: 0 10rpx;
			height: 260rpx;
			padding-bottom: 60rpx;
			overflow: hidden;
		}

		.avatar {
			width: 73rpx;
			height: 73rpx;
		}

		.lan-box {
			width: 140rpx;
			height: 39rpx;
			background: #FFFFFF;
			box-shadow: 2rpx 6rpx 6rpx 2rpx rgba(160, 24, 102, .1), inset 0rpx 0rpx 6rpx 0rpx rgba(0, 0, 0, .3);
			border-radius: 10rpx;
		}

		.message-icon {
			width: 30rpx;
			height: 21rpx;
		}

		.typeAvatar2 {
			width: 156rpx;
			height: 156rpx;
			margin-top: 120rpx;
		}

		.typeName2 {
			color: #FFFFFF;
			font-size: 30rpx;
		}

		.space-between {
			padding: 30rpx 33rpx 13rpx;
			height: 120rpx;
		}

		.logo {
			width: 55rpx;
			height: 55rpx;
		}

		.logo-box {
			width: 140rpx;
		}
	}
</style>